<?php
require_once('sub.inc.php');

if( $_SERVER['QUERY_STRING'] !== "" ){
	$code = clean($_SERVER['QUERY_STRING']);
	$res = mysqli_query($GLOBALS['con'], "SELECT `url`,`id` FROM `links` WHERE `code` LIKE BINARY '$code'");
	if( $row = mysqli_fetch_array($res) ){
		header('Location: '. $row['url'], 307);
		mysqli_query($GLOBALS['con'], "INSERT INTO `logs` (`event`, `relatedid`, `message`, `message2`, `ip`) VALUES ('HIT', '{$row['id']}', '{$_SERVER['HTTP_USER_AGENT']}', '{$_SERVER['HTTP_REFERER']}', '{$_SERVER['REMOTE_ADDR']}')");
	}else{
		print "Sorry, that's not a valid code.";
	}
}else{
	print "<h1>enwn.net v0.2</h1><br>URL Shortening by the <a href=\"http://en.wikinews.org\">English Wikinews</a> community."; 
}


?>
